<?php

/**
 * Class Home
 *
 * Please note:
 * Don't use the same name for class and method, as this might trigger an (unintended) __construct of the class.
 * This is really weird behaviour, but documented here: http://php.net/manual/en/language.oop5.decon.php
 *
 */
class Details extends Controller
{
    /**
     * PAGE: index
     * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
     */
    public function index(){
    	
    	// load a model, perform an action, pass the returned data to a variable
    	// NOTE: please write the name of the model "LikeThis"
    	$laptop_model = $this->loadModel('LaptopModel');
    	$count = $laptop_model->countLaptops();
    	$randid = rand(1,$count[0]->LAPCOUNT);
    	$special = $laptop_model->getLaptopById($randid);
    	$sold = $laptop_model->countSold();
    	
    	$laptopdetails = $laptop_model->getLaptopById(1);
    	$laptop = $laptopdetails[0];
        // debug message to show where you are, just for the demo
        // echo 'Message from Controller: You are in the controller home, using the method index()';
        require 'application/views/common/_header.php';
        require 'application/views/details/index.php';
        require 'application/views/common/_footer.php';
    }
    
    public function showDetails($itemid){
    	
    	$laptop_model = $this->loadModel('LaptopModel');
    	$count = $laptop_model->countLaptops();
    	$randid = rand(1,$count[0]->LAPCOUNT);
    	$special = $laptop_model->getLaptopById($randid);
    	$sold = $laptop_model->countSold();
    	
    	if (isset($itemid)) {
	    	$laptopdetails = $laptop_model->getLaptopById($itemid);
	    	$laptop = $laptopdetails[0];
    	}

        require './application/views/common/_header.php';
        require './application/views/details/index.php';
        require './application/views/common/_footer.php';
    }
}
